home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / bbs / low_1123.zip / MSGCNT11.ZIP / MSGCNT.CMD < prev   
OS/2 REXX Batch file  |  1996-10-07  |  8KB  |  223 lines

  1. /* MSGCNT.CMD - Program to count messages received 
  2.     version 1.1, 12 June, 1995 by Elliott Goodman 
  3.  
  4. I run this from my LOG.CMD program, run nightly during
  5. Lora's 'auto-maint' phase, the only time the logfile is free.
  6. If you are going to use LOG.CMD to run it, place it as follows:
  7.  
  8.         say 'Door Tracker....'                   
  9.         call Door_tracker                        
  10.                                                  
  11.         say "Running MSGCNT.CMD. Please wait...."
  12.         call "d:\lora\lang\msgcnt.cmd"
  13.                                                  
  14.         say 'Remove routine....'                 
  15.         call remove_stuff                        
  16.  
  17. Locate the two routines above and place it between them as
  18. shown with correct drive/path info.
  19.  
  20. Feel free to modify as needed.
  21. */
  22.  
  23. /* trace ?a */
  24.  
  25. /* load if not already loaded */
  26. if RxFuncQuery('SysLoadFuncs') then
  27. do
  28.         call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  29.         call SysLoadFuncs
  30. end
  31.  
  32. /* save directory info */
  33. old_dir = directory()
  34.  
  35. /* modify as necessary */
  36. call directory('D:\LORA\LANG')
  37.  
  38. /* initialize variables */
  39. phrase1 = 'Tossing'
  40. phrase2 = 'packet(s):'
  41.  
  42. in_name = 'lora.log'
  43. out_name = 'MSGCOUNT.TXT'
  44. toss_flag = 0
  45. toss_pattern = '(Toss='
  46. area_names = 0
  47. temp_name = ' '
  48. temp_count = 0
  49. total_count = 0
  50.  
  51. /* remove previous Output file, if present */
  52. call SysFileDelete(out_name)
  53.  
  54. drop messages.
  55.  
  56. /* Initialize Output file with date/time */
  57. m_txt = 'Message Count v1.0 by Elliott Goodman'
  58. call lineout out_name, m_txt
  59. m_txt = '  '
  60. call lineout out_name, m_txt
  61. time_string = time('C')
  62. date_string = date('N')
  63. m_txt = 'Current time:' time_string || ',' date_string
  64. call lineout out_name, m_txt
  65. m_txt = 'Messages received yesterday'
  66. call lineout out_name, m_txt
  67. m_txt = '  '
  68. call lineout out_name, m_txt
  69.  
  70. /* cycle thru LORA.LOG */
  71. do until lines(in_name) = 0
  72.     work_line = linein(in_name)
  73.  
  74. /* set further-work flag. This should avoid messing with
  75. irrelevant lines and speed things up */
  76.  
  77.     if toss_flag = 0 then do
  78.         j = wordpos(phrase1, work_line)
  79.         if j \= 0 then
  80.             toss_flag = 1
  81.         end /* if toss_flag <> 1 */
  82.  
  83.     if toss_flag = 1 then do
  84.         j = wordpos(phrase2, work_line)
  85.         if j \= 0 then
  86.             toss_flag = 0
  87.         end /* if toss_flag = 1 */
  88.  
  89. /* found block of lines headed by 'Tossing */
  90.     if toss_flag = 1 then do
  91. /* break up line into elements */
  92.         parse var work_line . . area_tag toss_count stuff
  93. /* if line contains (Toss=xxxx) then work on it */
  94.         if left(toss_count, 6) = '(Toss=' then do
  95.  
  96. /* remove trailing space, if present */
  97.             toss_count = strip(toss_count)
  98. /* remove leading '(Toss=' stuff */
  99.             parse var toss_count (toss_pattern) toss_count
  100. /* remove trailing ')' - should now be of form '000x' */
  101.             toss_count = strip(toss_count, 'T', ')' )
  102.  
  103. /* search thru array for area tag and increment if found */
  104.             found = 0
  105.             do index = 1 to area_names
  106.                 if messages.index = area_tag then do
  107.                     messages.index.count = messages.index.count + toss_count
  108.                     found = 1
  109.                     leave
  110.                     end /* if */
  111.                 end /* do index = 1 to area_names */
  112.  
  113. /* area tag not found; add to array */
  114.              if found = 0 then do
  115.                  area_names = area_names + 1
  116.                  messages.area_names = area_tag
  117.                  messages.area_names.count = toss_count
  118.                  end /* if found = 0 */
  119.             end /* if left = (Toss */
  120.         end /* if toss_flag = 1 */
  121.     end /* do until lines() = 0 */
  122.  
  123. /* sort routine - not fast but it works */
  124. swap = 1
  125. do until swap = 0
  126.     swap = 0
  127.     do index = 1 to area_names -1
  128.         t_index = index + 1
  129.         if messages.t_index.count > messages.index.count then do
  130.             temp_name = messages.index
  131.             temp_count = messages.index.count
  132.             messages.index = messages.t_index
  133.             messages.index.count = messages.t_index.count
  134.             messages.t_index = temp_name
  135.             messages.t_index.count = temp_count
  136.             swap = 1
  137.             end /* if */
  138.         end /* do */
  139.     end /* do until */
  140.  
  141. do index = 1 to area_names                                    
  142. /*   if messages.index.count > 999 then do                      
  143.        temp = trunc(messages.index.count)                     
  144.        thousands = temp % 1000                                
  145.        temp = temp // 1000                                    
  146.        select                                                 
  147.          when temp = 0 then                                   
  148.             temp = '000'                                      
  149.          when temp < 10 then                                  
  150.             temp = '00' || temp                               
  151.          when temp < 100 then                                 
  152.             temp = '0' || temp                                
  153.          otherwise                                            
  154.             nop                                               
  155.          end                                                  
  156.        messages.index.count.fmt = thousands || ',' || temp    
  157.        end                                                    
  158.    else                                                       
  159. */
  160.        messages.index.count.fmt = trunc(messages.index.count) 
  161.    end                                                        
  162.  
  163. /* Now output sorted results after formatting a little */             
  164. do index = 1 to area_names                                            
  165.    select
  166.       when messages.index.count > 9999 then
  167.          m_txt = space(messages.index,                                
  168.             messages.index.count.fmt,(23-length(messages.index)),' ') 
  169.       when messages.index.count > 999 then
  170.          m_txt = space(messages.index,
  171.             messages.index.count.fmt,(24-length(messages.index)),' ') 
  172.       when messages.index.count > 99 then
  173.          m_txt = space(messages.index,
  174.             messages.index.count.fmt,(25-length(messages.index)),' ') 
  175.       when messages.index.count > 9 then
  176.          m_txt = space(messages.index,
  177.             messages.index.count.fmt,(26-length(messages.index)),' ') 
  178.       otherwise
  179.          m_txt = space(messages.index,
  180.             messages.index.count.fmt,(27-length(messages.index)),' ') 
  181.       end
  182.    call lineout out_name, m_txt                                       
  183.    total_count = total_count + messages.index.count                   
  184.    end                                                                
  185.  
  186. m_txt = '  '
  187. call lineout out_name, m_txt
  188.  
  189. /* do some comma formatting with total_count */ 
  190. temp = total_count                              
  191. if temp > 999 then do                           
  192.   thousands = temp % 1000                       
  193.   temp = temp // 1000                           
  194.   end                                           
  195.  
  196. if thousands \= 'THOUSANDS' then do                                                
  197.    select                                                
  198.      when temp = 0 then                                  
  199.         temp = '000'                                     
  200.      when temp < 10 then                                 
  201.         temp = '00' || temp                              
  202.      when temp < 100 then                                
  203.         temp = '0' || temp                               
  204.      otherwise                                           
  205.         nop                                              
  206.      end                                                 
  207.    end
  208.  
  209. if thousands \= 'THOUSANDS' then                                                      
  210.    total_count = thousands || ',' || temp 
  211. else
  212.    total_count = temp
  213.  
  214. m_txt = space('Total' total_count,19,' ')
  215. call lineout out_name, m_txt
  216.  
  217. /* close files, return to starting directory, copy output to
  218. bulletin file */
  219. call lineout in_name
  220. call lineout out_name
  221. '@copy' out_name 'd:\lora\misc\BULLET6.BBS 1>NUL 2>&1' 
  222. call directory(old_dir)
  223.